902A - Visiting a Friend - CodeForces Solution


greedy implementation *1100

Please click on ads to support us..

Python Code:

inputs = [int(num) for num in input().split()]
n = inputs[0]
m = inputs[1]
inputs1 = [int(num) for num in input().split()]
start=inputs1[0]
max1 = inputs1[1]
if(start>0):
    print("NO")
else:
    i=1
    for i in range(1,n):
        inputs1 = [int(num) for num in input().split()]
        if(inputs1[0]>max1):
            break;
        else:
            if(inputs1[1]>max1):
                max1=inputs1[1]
            if(max1>=m):
                break
        

    if(max1>=m):
        print("YES")
    else:
        print("NO")

C++ Code:

#include <bits/stdc++.h>

#define int long long
#define float long double
#define testcases               \
    int T;                      \
    cin >> T;                   \
    for (int t = 0; t < T; t++) \
    {                           \
        solve();                \
    }
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL)
#define endl '\n'
#define tupsort(tupname, num) sort(tupname.begin(), tupname.end(), [num](const auto &lhs, const auto &rhs) { return get<num>(lhs) < get<num>(rhs); })
using namespace std;
const int INF = 2e9;
const int M = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef map<int, int> mii;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<pii> vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec[i].first >> vec[i].second;
    }
    int maxi = 0;
    for (int i = 0; i < n; i++)
    {
        if (maxi < vec[i].first)
        {
            cout << "NO\n";
            return;
        }
        if (vec[i].second >= m)
        {
            cout << "YES\n";
            return;
        }
        maxi = max(maxi, vec[i].second);
    }
    cout << "NO\n";
}

int32_t main()
{
    // #ifndef ONLINE_JUDGE
    //	freopen("input.txt", "r", stdin);
    //	freopen("output.txt", "w", stdout);
    // #endif
    fast;
    // testcases;
    solve();
}


Comments

Submit
0 Comments
More Questions

1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room
230A - Dragons
200B - Drinks
13A - Numbers
129A - Cookies
1367B - Even Array
136A - Presents
1450A - Avoid Trygub
327A - Flipping Game
411A - Password Check
1520C - Not Adjacent Matrix
1538B - Friends and Candies
580A - Kefa and First Steps
1038B - Non-Coprime Partition
43A - Football
50A - Domino piling
479A - Expression
1480A - Yet Another String Game
1216C - White Sheet
1648A - Weird Sum
427A - Police Recruits